<bean> id 配置重复, 重复的 id 是 person
1 | Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Bean name 'person' is already used in this <beans> element |
<bean> 并不是唯一的(一般出现在使用 getBean(类名.class)获取对象的时候 )
1 | Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.itguigu.spring.mod.Person] is defined: expected single matching bean but found 2: person,person2 |
Spring 利用的是反射来创建对象,使用 xml 中的 class 路径来加载类,并且调用反射中的 newInstance 方法来创建对象。而 newInstance 要求 Java bean 实体中必须要有无参构造方法。否则就会出现以下错误
1 | Caused by: java.lang.NoSuchMethodException: com.itguigu.spring.mod.Person.<init>() |
没有未 bean 指定 class
1 | Caused by: java.lang.IllegalStateException: No bean class specified on bean definition |
类型转换错误。
1 | Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [com.itguigu.spring.di.Student] for property 'students[0]': no matching editors or conversion strategy found |
找不到相对应的 bean
1 | Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userController1' is defined |
使用注解方式注入的时候经常会出现这种错误,这种一般是类上面没有加注解导致
1 | org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.itguigu.ioc.userMod.dao.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} |
表示 Spring 配置文件中存在语法错误或者找不到配置文件。Spring 默认找的是 WEB-INF 下面的 applicationContext.xml 文件。
1 | java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext |